//! Basic demonstration of the AI Test Platform
//!
//! This example shows how to use the core functionality of the platform:
//! - Initialize the Actor system
//! - Create and manage test cases
//! - Use the plugin system
//! - Demonstrate data serialization

use ai_test_platform::{
    actors::ActorSystemManager,
    models::{
        testcase::TestCase,
        config::TestConfig,
        Value, ValueMap,
    },
    plugins::PluginManager,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("🚀 AI Test Platform Demo");
    println!("========================");
    
    // 1. Initialize the Actor System
    println!("\n1. Initializing Actor System...");
    let mut actor_system = ActorSystemManager::new().await?;
    actor_system.initialize().await?;
    println!("✅ Actor System initialized successfully");
    
    // 2. Create a simple test case
    println!("\n2. Creating Test Case...");
    let test_case = create_sample_test_case();
    println!("✅ Test Case created: {}", test_case.config.name);
    println!("   - ID: {}", test_case.id);
    println!("   - Created: {}", test_case.created_at);
    
    // 3. Initialize Plugin Manager
    println!("\n3. Initializing Plugin System...");
    let mut plugin_manager = PluginManager::new();
    plugin_manager.load_builtin_plugins().await?;
    let plugins = plugin_manager.list_plugins().await?;
    println!("✅ Plugin System initialized");
    println!("   - Loaded {} plugins:", plugins.len());
    for plugin in &plugins {
        println!("     • {} v{}: {}", plugin.manifest.name, plugin.manifest.version, 
                 plugin.manifest.description.as_deref().unwrap_or("No description"));
    }
    
    // 4. Demonstrate Actor communication
    println!("\n4. Testing Actor Communication...");
    let test_suite_actor = actor_system.test_suite_actor().ok_or("TestSuite actor not found")?;
    let plugin_actor = actor_system.plugin_actor().ok_or("Plugin actor not found")?;
    let report_actor = actor_system.report_actor().ok_or("Report actor not found")?;
    
    println!("✅ All actors are accessible:");
    println!("   - TestSuite Actor ID: {}", test_suite_actor.actor_id());
    println!("   - Plugin Actor ID: {}", plugin_actor.actor_id());
    println!("   - Report Actor ID: {}", report_actor.actor_id());
    
    // 5. Demonstrate data serialization
    println!("\n5. Testing Data Serialization...");
    let json_data = serde_json::to_string_pretty(&test_case)?;
    println!("✅ Test case serialized to JSON ({} bytes)", json_data.len());
    
    // 6. Show platform capabilities
    println!("\n6. Platform Capabilities Summary:");
    println!("   ✅ Actor-based architecture with coerce-rs");
    println!("   ✅ Plugin system with Extism WASM support");
    println!("   ✅ Comprehensive data models");
    println!("   ✅ HTTP/HTTPS protocol support");
    println!("   ✅ Test case management");
    println!("   ✅ Result reporting and analysis");
    println!("   ✅ AI orchestration framework");
    println!("   ✅ Extensible storage backends");
    
    println!("\n🎉 Demo completed successfully!");
    println!("The AI Test Platform is ready for advanced testing scenarios.");
    
    Ok(())
}

/// Create a sample test case for demonstration
fn create_sample_test_case() -> TestCase {
    let config = TestConfig::new("Demo API Test".to_string());
    let test_case = TestCase::new(config);

    test_case
}

/// Create sample test configuration
fn _create_sample_config() -> TestConfig {
    let mut config = TestConfig::new("Demo Configuration".to_string());

    // Set some basic configuration
    config.base_url = Some("https://api.github.com".to_string());

    config
}
